<template>
    <div class="photoinfo-container">
      <div class="photoinfo-header">
        <h3>{{photosInfo.title}}</h3>
        <p class="subtitle">
            <span>发表时间：{{photosInfo.add_time|dateFormart}}</span>
            <span>点击：{{photosInfo.click}}次</span>
        </p>
      </div>
        <hr>
        <!-- 缩略图区域 -->
        <div class="thumb">
          <div class="thumbs">
            <img class="preview-img" v-for="(item, index) in list" :src="item.src" height="100" @click="$preview.open(index, list)" :key="item.src">
          </div>
          <!-- 图片内容区域 -->
          <div class="content" v-html="photosInfo.content"></div>
        </div>

        <!-- 评论子组件 -->
        <cmt-box :id="id"></cmt-box>
    </div>
</template>
<script>
import comment from "../subcomponents/comment.vue";

export default {
  data() {
    return {
      id: this.$route.params.id,
      photosInfo: {}, //图片信息
      list: []
    };
  },
  created() {
    this.getPhotoInfo();
    this.getThumbs()//方法请求回来的数据有丢失，暂时不使用该方法
  },

  methods: {
    getPhotoInfo() {
      this.$http.get("api/getimageInfo/" + this.id).then(result => {
        console.log(result.body.message);
        if (result.body.status === 0) {
          this.photosInfo = result.body.message[0];
        }
      });
    },
    getThumbs() {
      //获取缩略图
      this.$http.get("api/getthumimages/" + this.id).then(result => {
        console.log(result.body.message);
        if (result.body.status === 0) {
          //循环每个图片数据，补全图片的宽和高
          result.body.message.forEach(item => {
            item.img = item.img.replace("com", "com/");
            item.src = item.src.replace("com", "com/");
            item.w = 600;
            item.h = 400;
          });
          this.list = result.body.message;
          console.log(this.list);
        }
      });
    }
  },
  components: {
    "cmt-box": comment
  }
};
</script>
<style lang="scss" scoped>
.photoinfo-container {
  .photoinfo-header{
      margin: 0 10px;
  }
  padding: 3px;
  h3 {
    color: black;
    font-size: 15px;
    text-align: center;
    margin: 15px 0;
  }
  .subtitle {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
  }
  .content {
    font-size: 13px;
    line-height: 30px;
  }
  .thumb{
    margin:0 10px;
  }
  .thumbs {
    img{
      margin: 5px;
      box-shadow: 0 0 8px #999;
      width: 106px;
      height: 100px;
    } 
  }
}
  

</style>


